<?php

/**
 * @category   MM
 * @package    MM_Service
 */
class MM_Service_Admin_EventUser extends Mediad2_Service_Abstract
{
	/**
	 * 初始化
	 */
	public function init()
	{
		$this->setMapper('MM_Mapper_EventUser');
		$this->setModel('MM_Model_EventUser');
	}
	
	/**
	 * 获得指定eid的user(来宾)
	 * @param int $eid
	 * @param int $addtime
	 * @return Mediad2_Model_Result
	 */
	public function getEventUser($eid, $addtime)
	{
		try {
			$mapper = $this->getMapper();
			$sql = "
				select
					u.uid as uid,
					u.nickname as nickname,
					u.email as email,
					u.mobile as mobile,
					u.qq as qq,
					u.avatar as avatar,
					eu.addtime as addtime
				from mm.user u, mm.event_user eu
			";
			$where = " where u.uid = eu.uid and eu.eid = $eid and eu.isdel = 0  ";
			if (!empty($addtime)) {
				$where .= " and eu.addtime < $addtime";
			}
			$order = " order by eu.addtime desc";
			$limit = " limit 50";
			$sql = $sql . $where . $order . $limit;
			$results = $mapper->__querySQL($sql);
			return $this->returnResult(Mediad2_Model_Result::CODE_SUCCESS,null,$results);
		} catch (Exception $e) {
			$this->handleException($e);
			return $this->returnResult(Mediad2_Model_Result::CODE_FAILURE, $e->getMessage());
		}
	}
	
}